home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / oldwish / RCS / wishMain.c,v < prev    next >
Encoding:
Text File  |  1989-07-10  |  28.8 KB  |  1,161 lines

  1. head     1.4;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    mgbaker:1.4; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.4
  10. date     89.01.18.00.07.38;  author mgbaker;  state Exp;
  11. branches ;
  12. next     1.3;
  13.  
  14. 1.3
  15. date     89.01.11.11.58.21;  author mlgray;  state Exp;
  16. branches ;
  17. next     1.2;
  18.  
  19. 1.2
  20. date     88.11.02.14.50.49;  author mlgray;  state Exp;
  21. branches ;
  22. next     1.1;
  23.  
  24. 1.1
  25. date     88.10.03.12.48.21;  author mlgray;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29.  
  30. desc
  31. @X11: works pretty much now.
  32. @
  33.  
  34.  
  35. 1.4
  36. log
  37. @John changed mx/tx color interface, so I fixed wish.
  38. @
  39. text
  40. @/* 
  41.  * wishMain.c --
  42.  *
  43.  *    Main routine for wish stuff.
  44.  *
  45.  * Copyright 1987 Regents of the University of California
  46.  * All rights reserved.
  47.  * Permission to use, copy, modify, and distribute this
  48.  * software and its documentation for any purpose and without
  49.  * fee is hereby granted, provided that the above copyright
  50.  * notice appear in all copies.  The University of California
  51.  * makes no representations about the suitability of this
  52.  * software for any purpose.  It is provided "as is" without
  53.  * express or implied warranty.
  54.  */
  55.  
  56. #ifndef lint
  57. static char rcsid[] = "$Header: /a/newcmds/wish/RCS/wishMain.c,v 1.3 89/01/11 11:58:21 mlgray Exp Locker: mgbaker $ SPRITE (Berkeley)";
  58. #endif not lint
  59.  
  60. #include <X11/Xlib.h>
  61. #include <X11/Xutil.h>
  62. #define    Time    SpriteTime
  63. #include <sys/time.h>
  64. #include "string.h"
  65. #include <fs.h>
  66. #include "sx.h"
  67. #include "util.h"
  68. #include "monitorClient.h"
  69. #include "wishInt.h"
  70. #include <signal.h>
  71.  
  72. int    size;
  73.  
  74. /*
  75.  * The global table in which pointers to window information for each
  76.  * wish window is kept.
  77.  */
  78. XContext    wishWindowContext;
  79. XContext    wishGroupWindowContext;
  80.  
  81. /* Whether debugging is turned on or not */
  82. Boolean        wishDebugP = FALSE;
  83.  
  84. /* Whether the application should pick the initial window size */
  85. Boolean        wishPickSizeP = TRUE;
  86. /* whether the application can resize the window */
  87. Boolean        wishResizeP = FALSE;
  88. /* whether to display headers for groups with no files. */
  89. Boolean        wishShowEmptyGroupsP = FALSE;
  90. /* The display */
  91. Display        *wishDisplay;
  92.  
  93. /*
  94.  * The application name.
  95.  */
  96. char    *wishApplication = "wish";
  97.  
  98. /*
  99.  * For formulating error strings.  How big is big enough?
  100.  */
  101. char    wishErrorMsg[2 * MAXPATHLEN + 50];
  102.  
  103. /* Display info for calculating max size of windows */
  104. int        wishRootHeight;
  105. int        wishRootWidth;
  106.  
  107. /* Keep track of current directory. */
  108. char    wishCurrentDirectory[MAXPATHLEN + 1];
  109.  
  110. /*
  111.  * Wish's startup directory in which to look for the default .files if there
  112.  * aren't others.
  113.  */
  114. char    wishStartUp[MAXPATHLEN];
  115.  
  116. #ifdef ICON
  117. /*
  118.  * Icon window information.
  119.  */
  120.  
  121. #define ICONDIR    "/usr2/icon/X"
  122.  
  123. typedef struct {
  124.     int x;            /* Initial X, Y positions. */
  125.     int y;            
  126.     int width;
  127.     int height;
  128.     int foreground;        /* Foreground, background colors 
  129.                  * are same as the main window. */
  130.     int background;
  131.     char *name;            /* Filename of the icon bitmap file. */
  132.     Pixmap bitmap;        /* Bitmap data. */
  133.     Window window;        /* ID of the icon window. */
  134. } TxIconInfo;
  135. static TxIconInfo iconInfo = { 0, 0, 0, 0, 0, 0, NULL, NULL,};
  136. static void CreateIcon();
  137. #endif /* ICON */
  138.  
  139.  
  140. /*
  141.  *----------------------------------------------------------------------
  142.  *
  143.  * main --
  144.  *
  145.  *    Main routine for wish.
  146.  *
  147.  * Results:
  148.  *    None.
  149.  *
  150.  * Side effects:
  151.  *    Many.
  152.  *
  153.  *----------------------------------------------------------------------
  154.  */
  155. main(argc, argv)
  156.     int    argc;
  157.     char    *argv[];
  158. {
  159.     char    *string;
  160.     char    *geometry = NULL;    /* for window set-up */
  161.     char    *font;
  162.     WishWindow    *aWindow = NULL;
  163.     char    *startDir = NULL;
  164.     int        displayMask = 0;
  165.     int        numFDs;
  166. #ifdef NOTDEF
  167.     struct    timeval    alarm;
  168. #else /* NOTDEF */
  169.     SpriteTime    alarm;
  170. #endif /* NOTDEF */
  171.     int        monitorMask;
  172.     char    *cPtr;
  173.     extern    void    HandleMonitorEvent();
  174.     extern    void    WishDisplayEventProc();
  175.     extern    void    HandleMonitorStats();
  176.  
  177.     /*
  178.      * Process command line arguments.
  179.      */
  180.     while (argc > 1 ) { 
  181.     argc--;
  182.     argv++;
  183.     if (strcmp(argv[0], "-debug") == 0) {
  184.         wishDebugP = TRUE;
  185.         continue;
  186.     }
  187.     if (strcmp(argv[0], "-nopick") == 0) {
  188.         wishPickSizeP = FALSE;
  189.         continue;
  190.     }
  191.     if (strcmp(argv[0], "-resize") == 0) {
  192.         wishResizeP = TRUE;
  193.         continue;
  194.     }
  195.     if (strcmp(argv[0], "-empty") == 0) {
  196.         wishShowEmptyGroupsP = TRUE;
  197.         continue;
  198.     }
  199.     if (strcmp(argv[0], "-usage") == 0 ||
  200.         strcmp(argv[0], "-u") == 0) {
  201.         fprintf(stderr, "%s\n\n%s\n%s\n%s\n%s\n",
  202.             "wish -debug -nopick -resize -empty -usage dirname",
  203.             "-debug    Print debug messages and don't fork.",
  204.             "-nopick    Don't automatically pick initial window size.",
  205.             "-resize    Allow automatic resizing of window.",
  206.             "-empty    Display headers for groups without entries.");
  207.         exit(1);
  208.     }
  209.     startDir = argv[0];
  210.     }
  211.     /* get directory in which we're starting up */
  212.     (void) Whence(wishStartUp, argv[0]);
  213.  
  214.     /* Don't fork into background if debugging is on - so dbx works, etc. */
  215.     if (!wishDebugP) {
  216.     Proc_Detach(0);
  217.     }
  218.     /*
  219.      * Initialize the display and wishWindowContext and
  220.      * wishGroupWindowContext.
  221.      */
  222.     if ((wishDisplay = XOpenDisplay(NULL)) == NULL) {
  223.     fprintf(stderr, "Could not open display.\n");
  224.     exit(1);
  225.     }
  226.     if (wishDebugP) {
  227.     XSynchronize(wishDisplay, True);
  228.     }
  229.     Sx_SetErrorHandler();
  230.  
  231.     wishRootHeight = DisplayHeight(wishDisplay,
  232.         DefaultScreen(wishDisplay));
  233.     wishRootWidth = DisplayWidth(wishDisplay,
  234.         DefaultScreen(wishDisplay));
  235.  
  236.     /*
  237.      * 8 should be more than enough considering there's only 1 window
  238.      * right now!
  239.      */
  240.     wishWindowContext = XUniqueContext();
  241.     wishGroupWindowContext = XUniqueContext();
  242.  
  243.     /*
  244.      * Create a dummy structure for passing to WishCreate to create
  245.      * the first window and then process XDefault arguments.  
  246.      */
  247.     aWindow = (WishWindow *) malloc(sizeof (WishWindow));
  248.     
  249.     if (startDir != NULL) {
  250.     if (Util_CanonicalDir(startDir, NULL, aWindow->dir) == NULL) {
  251.         /* error message returned in aWindow->dir */
  252.         Sx_Panic(wishDisplay, aWindow->dir);
  253.     }
  254.     } else if (getwd(aWindow->dir) == NULL) {
  255.     sprintf(wishErrorMsg,
  256.         "%s: Couldn't get current working directory.\n",
  257.         wishApplication);
  258.     Sx_Panic(wishDisplay, wishErrorMsg);
  259.     }
  260.  
  261.     if ((string = XGetDefault(wishDisplay, wishApplication,
  262.         "Background")) != NULL) {
  263.     if ((aWindow->background =
  264.         Util_StringToColor(wishDisplay, string)) == -1) {
  265.         aWindow->background = BlackPixel(wishDisplay,
  266.             DefaultScreen(wishDisplay));
  267.     }
  268.     } else {
  269.     aWindow->background = BlackPixel(wishDisplay,
  270.         DefaultScreen(wishDisplay));
  271.     }
  272.  
  273.     if ((string = XGetDefault(wishDisplay, wishApplication,
  274.         "Foreground")) != NULL) {
  275.     if ((aWindow->foreground =
  276.         Util_StringToColor(wishDisplay, string)) == -1) {
  277.         /* Try to make it the opposite of the background */
  278.         if (aWindow->background == WhitePixel(wishDisplay,
  279.             DefaultScreen(wishDisplay))) {
  280.         aWindow->foreground = BlackPixel(wishDisplay,
  281.             DefaultScreen(wishDisplay));
  282.         } else {
  283.         aWindow->foreground = WhitePixel(wishDisplay,
  284.             DefaultScreen(wishDisplay));
  285.         }
  286.     }    
  287.     /* At least try to make it the opposite of the background */
  288.     } else if (aWindow->background == WhitePixel(wishDisplay,
  289.         DefaultScreen(wishDisplay))) {
  290.     aWindow->foreground = BlackPixel(wishDisplay,
  291.         DefaultScreen(wishDisplay));
  292.     } else {
  293.     aWindow->foreground = WhitePixel(wishDisplay,
  294.         DefaultScreen(wishDisplay));
  295.     }
  296.  
  297.     if ((string = XGetDefault(wishDisplay, wishApplication, "Border"))
  298.         != NULL) {
  299.     if ((aWindow->border =
  300.         Util_StringToColor(wishDisplay, string)) == -1) {
  301.         /* Try to make it the opposite of the background */
  302.         if (aWindow->background == WhitePixel(wishDisplay,
  303.             DefaultScreen(wishDisplay))) {
  304.         aWindow->border = BlackPixel(wishDisplay,
  305.             DefaultScreen(wishDisplay));
  306.         } else {
  307.         aWindow->border = WhitePixel(wishDisplay,
  308.             DefaultScreen(wishDisplay));
  309.         }
  310.     }
  311.     /* At least try to make it the opposite of the background */
  312.     } else if (aWindow->background == WhitePixel(wishDisplay,
  313.         DefaultScreen(wishDisplay))) {
  314.     aWindow->border = BlackPixel(wishDisplay,
  315.         DefaultScreen(wishDisplay));
  316.     } else {
  317.     aWindow->border = WhitePixel(wishDisplay,
  318.         DefaultScreen(wishDisplay));
  319.     }
  320.  
  321.     if ((string = XGetDefault(wishDisplay, wishApplication, "Selection"))
  322.         != NULL) {
  323.     if ((aWindow->selection =
  324.         Util_StringToColor(wishDisplay, string)) == -1) {
  325.         /* Try to make it the opposite of the background */
  326.         if (aWindow->background == WhitePixel(wishDisplay,
  327.             DefaultScreen(wishDisplay))) {
  328.         aWindow->selection = BlackPixel(wishDisplay,
  329.             DefaultScreen(wishDisplay));
  330.         } else {
  331.         aWindow->selection = WhitePixel(wishDisplay,
  332.             DefaultScreen(wishDisplay));
  333.         }
  334.     }    
  335.     /* At least try to make it the opposite of the background */
  336.     } else if (aWindow->background == WhitePixel(wishDisplay,
  337.         DefaultScreen(wishDisplay))) {
  338.     aWindow->selection = BlackPixel(wishDisplay,
  339.         DefaultScreen(wishDisplay));
  340.     } else {
  341.     aWindow->selection = WhitePixel(wishDisplay,
  342.         DefaultScreen(wishDisplay));
  343.     }
  344.  
  345.     if ((string = XGetDefault(wishDisplay, wishApplication,
  346.         "TitleBackground")) != NULL) {
  347.     if ((aWindow->titleBackground =
  348.         Util_StringToColor(wishDisplay, string)) == -1) {
  349.         aWindow->titleBackground = aWindow->background;
  350.     }
  351.     } else {
  352.     aWindow->titleBackground = aWindow->background;
  353.     }
  354.  
  355.     if ((string = XGetDefault(wishDisplay, wishApplication,
  356.         "TxBackground")) != NULL) {
  357.     if ((aWindow->txBackground =
  358.         Util_StringToColor(wishDisplay, string)) == -1) {
  359.         aWindow->txBackground = aWindow->background;
  360.     }
  361.     } else {
  362.     aWindow->txBackground = aWindow->background;
  363.     }
  364.     if ((string = XGetDefault(wishDisplay, wishApplication,
  365.         "MenuBackground")) != NULL) {
  366.     if ((aWindow->menuBackground =
  367.         Util_StringToColor(wishDisplay, string)) == -1) {
  368.         aWindow->menuBackground = aWindow->background;
  369.     }
  370.     } else {
  371.     aWindow->menuBackground = aWindow->background;
  372.     }
  373.     if ((string = XGetDefault(wishDisplay, wishApplication,
  374.         "SortBackground")) != NULL) {
  375.     if ((aWindow->sortBackground =
  376.         Util_StringToColor(wishDisplay, string)) == -1) {
  377.         aWindow->sortBackground = aWindow->background;
  378.     }
  379.     } else {
  380.     aWindow->sortBackground = aWindow->background;
  381.     }
  382.     if ((string = XGetDefault(wishDisplay, wishApplication,
  383.         "FieldsBackground")) != NULL) {
  384.     if ((aWindow->fieldsBackground =
  385.         Util_StringToColor(wishDisplay, string)) == -1) {
  386.         aWindow->fieldsBackground = aWindow->background;
  387.     }
  388.     } else {
  389.     aWindow->fieldsBackground = aWindow->background;
  390.     }
  391.  
  392.     if ((string = XGetDefault(wishDisplay, wishApplication,
  393.         "EntryBackground")) != NULL) {
  394.     if ((aWindow->entryBackground =
  395.         Util_StringToColor(wishDisplay, string)) == -1) {
  396.         aWindow->entryBackground = aWindow->background;
  397.     }
  398.     } else {
  399.     aWindow->entryBackground = aWindow->background;
  400.     }
  401.  
  402.     if ((string = XGetDefault(wishDisplay, wishApplication,
  403.         "ScrollBackground")) != NULL) {
  404.     if ((aWindow->scrollBackground =
  405.         Util_StringToColor(wishDisplay, string)) == -1) {
  406.         aWindow->scrollBackground = aWindow->background;
  407.     }
  408.     } else {
  409.     aWindow->scrollBackground = aWindow->background;
  410.     }
  411.  
  412.     if ((string = XGetDefault(wishDisplay, wishApplication,
  413.         "TitleForeground")) != NULL) {
  414.     if ((aWindow->titleForeground =
  415.         Util_StringToColor(wishDisplay, string)) == -1) {
  416.         aWindow->titleForeground = aWindow->foreground;
  417.     }    
  418.     } else {
  419.     aWindow->titleForeground = aWindow->foreground;
  420.     }
  421.  
  422.     if ((string = XGetDefault(wishDisplay, wishApplication,
  423.         "TxForeground")) != NULL) {
  424.     if ((aWindow->txForeground =
  425.         Util_StringToColor(wishDisplay, string)) == -1) {
  426.         aWindow->txForeground = aWindow->foreground;
  427.     }    
  428.     } else {
  429.     aWindow->txForeground = aWindow->foreground;
  430.     }
  431.  
  432.     if ((string = XGetDefault(wishDisplay, wishApplication,
  433.         "MenuForeground")) != NULL) {
  434.     if ((aWindow->menuForeground =
  435.         Util_StringToColor(wishDisplay, string)) == -1) {
  436.         aWindow->menuForeground = aWindow->foreground;
  437.     }
  438.     } else {
  439.     aWindow->menuForeground = aWindow->foreground;
  440.     }
  441.  
  442.     if ((string = XGetDefault(wishDisplay, wishApplication,
  443.         "SortForeground")) != NULL) {
  444.     if ((aWindow->sortForeground =
  445.         Util_StringToColor(wishDisplay, string)) == -1) {
  446.         aWindow->sortForeground = aWindow->foreground;
  447.     }    
  448.     } else {
  449.     aWindow->sortForeground = aWindow->foreground;
  450.     }
  451.  
  452.     if ((string = XGetDefault(wishDisplay, wishApplication,
  453.         "FieldsForeground")) != NULL) {
  454.     if ((aWindow->fieldsForeground =
  455.         Util_StringToColor(wishDisplay, string)) == -1) {
  456.         aWindow->fieldsForeground = aWindow->foreground;
  457.     }    
  458.     } else {
  459.     aWindow->fieldsForeground = aWindow->foreground;
  460.     }
  461.  
  462.     if ((string = XGetDefault(wishDisplay, wishApplication,
  463.         "EntryForeground")) != NULL) {
  464.     if ((aWindow->entryForeground =
  465.         Util_StringToColor(wishDisplay, string)) == -1) {
  466.         aWindow->entryForeground = aWindow->foreground;
  467.     }    
  468.     } else {
  469.     aWindow->entryForeground = aWindow->foreground;
  470.     }
  471.  
  472.     if ((string = XGetDefault(wishDisplay, wishApplication,
  473.         "ScrollForeground")) != NULL) {
  474.     if ((aWindow->scrollForeground =
  475.         Util_StringToColor(wishDisplay, string)) == -1) {
  476.         aWindow->scrollForeground = aWindow->foreground;
  477.     }    
  478.     } else {
  479.     aWindow->scrollForeground = aWindow->foreground;
  480.     }
  481.  
  482.     if ((string = XGetDefault(wishDisplay, wishApplication,
  483.         "BorderWidth")) != NULL) {
  484.     if ((aWindow->borderWidth = strtol(string, &cPtr, 10)) == 0 &&
  485.         cPtr == string) {
  486.         /* AtoI failed */
  487.         aWindow->borderWidth = 2;
  488.     }
  489.     } else {
  490.     aWindow->borderWidth = 2;
  491.     }
  492.  
  493.     if ((string = XGetDefault(wishDisplay, wishApplication,
  494.         "TitleBorder")) != NULL) {
  495.     if ((aWindow->titleBorder =
  496.         Util_StringToColor(wishDisplay, string)) == -1) {
  497.         aWindow->titleBorder = aWindow->border;
  498.     }
  499.     } else {
  500.     aWindow->titleBorder = aWindow->border;
  501.     }
  502.  
  503.     if ((string = XGetDefault(wishDisplay, wishApplication, "TxBorder"))
  504.         != NULL) {
  505.     if ((aWindow->txBorder =
  506.         Util_StringToColor(wishDisplay, string)) == -1) {
  507.         aWindow->txBorder = aWindow->border;
  508.     }
  509.     } else {
  510.     aWindow->txBorder = aWindow->border;
  511.     }
  512.  
  513.     if ((string = XGetDefault(wishDisplay, wishApplication,
  514.         "ScrollElevator")) != NULL) {
  515.     if ((aWindow->scrollElevator =
  516.         Util_StringToColor(wishDisplay, string)) == -1) {
  517.         aWindow->scrollElevator = aWindow->scrollForeground;
  518.     }    
  519.     } else {
  520.     aWindow->scrollElevator = aWindow->scrollForeground;
  521.     }
  522.  
  523.     if ((geometry = XGetDefault(wishDisplay, wishApplication, "Geometry"))
  524.         == NULL) {
  525.     geometry = "=550x350+160+160";
  526.     }
  527.     aWindow->geometry = geometry;
  528.  
  529.     if ((font = XGetDefault(wishDisplay, wishApplication, "Font"))
  530.         != NULL) {
  531.     aWindow->fontPtr = XLoadQueryFont(wishDisplay, font);
  532.     if (aWindow->fontPtr != NULL) {
  533.         Sx_SetDefaultFont(aWindow->fontPtr);
  534.     } else {
  535.         aWindow->fontPtr = Sx_GetDefaultFont(wishDisplay);
  536.     }
  537.     } else {
  538.     aWindow->fontPtr = Sx_GetDefaultFont(wishDisplay);
  539.     }
  540.  
  541.     if ((font = XGetDefault(wishDisplay, wishApplication, "TitleFont"))
  542.         != NULL) {
  543.     aWindow->titleFontPtr = XLoadQueryFont(wishDisplay, font);
  544.     if (aWindow->titleFontPtr != NULL) {
  545.         Sx_SetDefaultFont(aWindow->titleFontPtr);
  546.     }
  547.     }
  548.     if (aWindow->titleFontPtr == NULL) {
  549.     aWindow->titleFontPtr = Sx_GetDefaultFont(wishDisplay);
  550.     }
  551.  
  552.     aWindow->interp = NULL;
  553.  
  554.     if (!MonClient_Register()) {
  555.     Sx_Panic(wishDisplay,
  556.         "Initialization of file system monitor failed.");
  557.     }
  558.  
  559.     /* create the first window */
  560.     if (startDir != NULL) {
  561.     if (WishCreate(aWindow, startDir) == NULL) {
  562.         Sx_Panic(wishDisplay, "Couldn't create flat display window.");
  563.     }
  564.     } else {
  565.     if (WishCreate(aWindow, NULL) == NULL) {
  566.         Sx_Panic(wishDisplay, "Couldn't create flat display window.");
  567.     }
  568.     }
  569.     free(aWindow);        /* free dummy structure */
  570.  
  571. #ifdef ICON
  572.     /*
  573.      * Create the icon for the window. This must done after the
  574.      * main window is initialized.
  575.      */
  576.  
  577.     CreateIcon(display, window, info.foreground, info.background);
  578. #endif /* ICON */
  579.  
  580.     alarm.seconds = 5;
  581.     alarm.microseconds = 0;
  582.     Fs_EventHandlerCreate(monClient_ReadPort, FS_READABLE,
  583.         HandleMonitorEvent, NULL);
  584.     Fs_EventHandlerCreate(ConnectionNumber(wishDisplay), FS_READABLE,
  585.         WishDisplayEventProc, NULL);
  586.     Fs_TimeoutHandlerCreate(alarm, TRUE, HandleMonitorStats,
  587.         (ClientData) NULL);
  588.     while (wishWindowCount > 0) {
  589.     while ((size = QLength(wishDisplay)) > 0) {
  590.         XEvent    event;
  591.  
  592.         XNextEvent(wishDisplay, &event);
  593.         Sx_HandleEvent(&event);
  594.     }
  595.     Tx_FlushStreams();
  596.     Tx_Update();
  597.     Mx_Update();
  598.     if ((size = QLength(wishDisplay)) > 0) {
  599.         continue;
  600.     }
  601.     XFlush(wishDisplay);
  602.     Fs_Dispatch();
  603.     }
  604.  
  605. # ifdef NOTDEF
  606. /*
  607.  * Can't do this yet.  I don't know what I'll do about the utmp
  608.  * stuff for now.
  609.  */
  610.     if (txRegisterPty) {
  611.     char    *ptyName;
  612.    
  613.     if ((ptyName = TxWindowToPtyName(window)) != NULL) {
  614.         (void) TxUtmpEntry(FALSE, ptyName, (char *) NULL);
  615.     }
  616.     }
  617. # endif /* NOTDEF */
  618.     exit(0);
  619. }
  620.  
  621.  
  622. void
  623. WishDisplayEventProc(clientData, streamID, eventMask)
  624.     ClientData    clientData;
  625.     int        streamID;
  626.     int        eventMask;
  627. {
  628.     static    int    count = 0;
  629.     XEvent    event;
  630.  
  631.     do {
  632.     count++;
  633.     XNextEvent(wishDisplay, &event);
  634.     Sx_HandleEvent(&event);
  635.     } while (QLength(wishDisplay) > 0);
  636.  
  637.     return;
  638. }
  639.  
  640. void
  641. HandleMonitorStats(clientData, time)
  642.     ClientData    clientData;
  643.     SpriteTime    time;
  644. {
  645.     Mon_StatDirs();
  646.     return;
  647. }
  648.  
  649. void
  650. HandleMonitorEvent(clientData, streamID, eventMask)
  651.     ClientData    clientData;
  652.     int        streamID;
  653.     int        eventMask;
  654. {
  655.     WishHandleMonitorUpdates();
  656.     return;
  657. }
  658.  
  659. #ifdef ICON
  660.  
  661. /*
  662.  *----------------------------------------------------------------------
  663.  *
  664.  * CreateIcon --
  665.  *
  666.  *    This procedure creates an icon window for the main window 
  667.  *    using data read in from a X bitmap file.
  668.  *
  669.  *    If the icon file name is "localhost", the hostname of the machine
  670.  *    is used to locate an icon file for the host in a standard directory.
  671.  *
  672.  * Results:
  673.  *    None.
  674.  *
  675.  * Side effects:
  676.  *    An icon window is created.
  677.  *
  678.  *----------------------------------------------------------------------
  679.  */
  680.  
  681. static void
  682. CreateIcon(display, window, foreground, background)
  683.     Display    *display;
  684.     Window window;        /* An icon will be created for this window. */
  685.     unsigned long foreground;    /* Foreground color of the icon. */
  686.     unsigned long background;    /* Background color of the icon. */
  687. {
  688.     char iconfile[256];        /* Buffer to hold a complete icon file name. */
  689.     char hostname[100];        /* Buffer to hold the hostname. */
  690.     char *dot;
  691.     int status;
  692.     XWMHints hints;
  693.  
  694.     /*
  695.      * See if a icon file name was given on the command line or is in the
  696.      * .Xdefaults file.
  697.      */
  698.     if (iconInfo.name == (char *) NULL) {
  699.     iconInfo.name = XGetDefault(display, "tx", "icon");
  700.     if (iconInfo.name == (char *) NULL) {
  701.         return;
  702.     }
  703.     }
  704.  
  705.     /*
  706.      * If the file name is localhost, look in a standard directory for
  707.      * a file named after the host.
  708.      */
  709.     if (strcmp(iconInfo.name, "localhost") == 0) {
  710.     gethostname(hostname, sizeof(hostname));
  711.     dot = strchr(hostname, '.');
  712.     if (dot != (char *) NULL) {
  713.         *dot = '\0';
  714.     }
  715.     sprintf(iconfile, "%s/%s", ICONDIR, hostname);
  716.     iconInfo.name = iconfile;
  717.     }
  718.  
  719.     status = XReadBitmapFile(display, window, iconInfo.name, &iconInfo.width,
  720.         &iconInfo.height, &iconInfo.bitmap, 0, 0);
  721.  
  722.     if (status == 0) {
  723.     fprintf(stderr,
  724.         "Tx: can't open icon file %s, using default icon.\n", 
  725.         iconInfo.name);
  726.     return;
  727.     } else if (status < 0) {
  728.     fprintf(stderr, 
  729.         "Tx: icon file %s has invalid format.\n", iconInfo.name);
  730.     return;
  731.     }
  732.  
  733.     hints.flags = InputHint|StateHint|IconWindowHint
  734.         |IconPixmapHint|IconPositionHint;
  735.     hints.input = False;
  736.     hints.icon_pixmap = iconInfo.bitmap;
  737.     hints.icon_window = XCreateSimpleWindow(display,
  738.         RootWindow(display, DefaultScreen(display)),
  739.         iconInfo.x, iconInfo.y, iconInfo.width, iconInfo.height,
  740.         0, foreground, background);
  741.     hints.icon_x = iconInfo.x;
  742.     hints.icon_y = iconInfo.y;
  743.     XSetWMHints(display, window, &hints);
  744.  
  745. #ifdef notdef    /* Shouldn't be needed under X11. */
  746.     (void) Sx_HandlerCreate(display, iconInfo.window, ExposureMask,
  747.         RefreshIcon, (ClientData) 0);
  748. #endif
  749. }
  750. #endif /* ICON */
  751. @
  752.  
  753.  
  754. 1.3
  755. log
  756. @Temporary checkin
  757. @
  758. text
  759. @d4 1
  760. a4 2
  761.  *    Main routine for wish stuff.  Right now I'm just testing the
  762.  *    new scrollbar stuff.
  763. d18 1
  764. a18 1
  765. static char rcsid[] = "$Header: /a/newcmds/wish/RCS/wishMain.c,v 1.2 88/11/02 14:50:49 mlgray Exp Locker: mlgray $ SPRITE (Berkeley)";
  766. @
  767.  
  768.  
  769. 1.2
  770. log
  771. @fsflat changed to wish
  772. @
  773. text
  774. @d19 1
  775. a19 1
  776. static char rcsid[] = "$Header: wishMain.c,v 1.1 88/10/03 12:48:21 mlgray Exp $ SPRITE (Berkeley)";
  777. d72 6
  778. d173 3
  779. @
  780.  
  781.  
  782. 1.1
  783. log
  784. @Initial revision
  785. @
  786. text
  787. @d2 1
  788. a2 1
  789.  * fsflatMain.c --
  790. d4 1
  791. a4 1
  792.  *    Main routine for fsflat stuff.  Right now I'm just testing the
  793. d19 1
  794. a19 1
  795. static char rcsid[] = "$Header: fsflatMain.c,v 1.11 88/06/10 13:15:07 mlgray Exp $ SPRITE (Berkeley)";
  796. d31 1
  797. a31 1
  798. #include "fsflatInt.h"
  799. d38 1
  800. a38 1
  801.  * fsflat window is kept.
  802. d40 2
  803. a41 2
  804. XContext    fsflatWindowContext;
  805. XContext    fsflatGroupWindowContext;
  806. d44 1
  807. a44 1
  808. Boolean        fsflatDebugP = FALSE;
  809. d47 1
  810. a47 1
  811. Boolean        fsflatPickSizeP = TRUE;
  812. d49 1
  813. a49 1
  814. Boolean        fsflatResizeP = FALSE;
  815. d51 1
  816. a51 1
  817. Boolean        fsflatShowEmptyGroupsP = FALSE;
  818. d53 1
  819. a53 1
  820. Display        *fsflatDisplay;
  821. d58 1
  822. a58 1
  823. char    *fsflatApplication = "fsflat";
  824. d63 1
  825. a63 1
  826. char    fsflatErrorMsg[2 * MAXPATHLEN + 50];
  827. d66 2
  828. a67 2
  829. int        fsflatRootHeight;
  830. int        fsflatRootWidth;
  831. d70 1
  832. a70 1
  833. char    fsflatCurrentDirectory[MAXPATHLEN + 1];
  834. d72 23
  835. d101 1
  836. a101 1
  837.  *    Main routine for fsflat.
  838. d118 1
  839. a118 1
  840.     FsflatWindow    *aWindow = NULL;
  841. d130 1
  842. a130 1
  843.     extern    void    FsflatDisplayEventProc();
  844. d140 1
  845. a140 1
  846.         fsflatDebugP = TRUE;
  847. d144 1
  848. a144 1
  849.         fsflatPickSizeP = FALSE;
  850. d148 1
  851. a148 1
  852.         fsflatResizeP = TRUE;
  853. d152 1
  854. a152 1
  855.         fsflatShowEmptyGroupsP = TRUE;
  856. d158 1
  857. a158 1
  858.             "fsflat -debug -nopick -resize -empty -usage dirname",
  859. d168 1
  860. a168 1
  861.     if (!fsflatDebugP) {
  862. d172 2
  863. a173 2
  864.      * Initialize the display and fsflatWindowContext and
  865.      * fsflatGroupWindowContext.
  866. d175 1
  867. a175 1
  868.     if ((fsflatDisplay = XOpenDisplay(NULL)) == NULL) {
  869. d179 2
  870. a180 2
  871.     if (fsflatDebugP) {
  872.     XSynchronize(fsflatDisplay, True);
  873. d184 4
  874. a187 4
  875.     fsflatRootHeight = DisplayHeight(fsflatDisplay,
  876.         DefaultScreen(fsflatDisplay));
  877.     fsflatRootWidth = DisplayWidth(fsflatDisplay,
  878.         DefaultScreen(fsflatDisplay));
  879. d193 2
  880. a194 2
  881.     fsflatWindowContext = XUniqueContext();
  882.     fsflatGroupWindowContext = XUniqueContext();
  883. d197 1
  884. a197 1
  885.      * Create a dummy structure for passing to FsflatCreate to create
  886. d200 1
  887. a200 1
  888.     aWindow = (FsflatWindow *) malloc(sizeof (FsflatWindow));
  889. d205 1
  890. a205 1
  891.         Sx_Panic(fsflatDisplay, aWindow->dir);
  892. d208 1
  893. a208 1
  894.     sprintf(fsflatErrorMsg,
  895. d210 2
  896. a211 2
  897.         fsflatApplication);
  898.     Sx_Panic(fsflatDisplay, fsflatErrorMsg);
  899. d214 1
  900. a214 1
  901.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  902. d217 3
  903. a219 3
  904.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  905.         aWindow->background = BlackPixel(fsflatDisplay,
  906.             DefaultScreen(fsflatDisplay));
  907. d222 2
  908. a223 2
  909.     aWindow->background = BlackPixel(fsflatDisplay,
  910.         DefaultScreen(fsflatDisplay));
  911. d226 1
  912. a226 1
  913.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  914. d229 1
  915. a229 1
  916.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  917. d231 4
  918. a234 4
  919.         if (aWindow->background == WhitePixel(fsflatDisplay,
  920.             DefaultScreen(fsflatDisplay))) {
  921.         aWindow->foreground = BlackPixel(fsflatDisplay,
  922.             DefaultScreen(fsflatDisplay));
  923. d236 2
  924. a237 2
  925.         aWindow->foreground = WhitePixel(fsflatDisplay,
  926.             DefaultScreen(fsflatDisplay));
  927. d241 4
  928. a244 4
  929.     } else if (aWindow->background == WhitePixel(fsflatDisplay,
  930.         DefaultScreen(fsflatDisplay))) {
  931.     aWindow->foreground = BlackPixel(fsflatDisplay,
  932.         DefaultScreen(fsflatDisplay));
  933. d246 2
  934. a247 2
  935.     aWindow->foreground = WhitePixel(fsflatDisplay,
  936.         DefaultScreen(fsflatDisplay));
  937. d250 1
  938. a250 1
  939.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication, "Border"))
  940. d253 1
  941. a253 1
  942.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  943. d255 4
  944. a258 4
  945.         if (aWindow->background == WhitePixel(fsflatDisplay,
  946.             DefaultScreen(fsflatDisplay))) {
  947.         aWindow->border = BlackPixel(fsflatDisplay,
  948.             DefaultScreen(fsflatDisplay));
  949. d260 2
  950. a261 2
  951.         aWindow->border = WhitePixel(fsflatDisplay,
  952.             DefaultScreen(fsflatDisplay));
  953. d265 4
  954. a268 4
  955.     } else if (aWindow->background == WhitePixel(fsflatDisplay,
  956.         DefaultScreen(fsflatDisplay))) {
  957.     aWindow->border = BlackPixel(fsflatDisplay,
  958.         DefaultScreen(fsflatDisplay));
  959. d270 2
  960. a271 2
  961.     aWindow->border = WhitePixel(fsflatDisplay,
  962.         DefaultScreen(fsflatDisplay));
  963. d274 1
  964. a274 1
  965.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication, "Selection"))
  966. d277 1
  967. a277 1
  968.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  969. d279 4
  970. a282 4
  971.         if (aWindow->background == WhitePixel(fsflatDisplay,
  972.             DefaultScreen(fsflatDisplay))) {
  973.         aWindow->selection = BlackPixel(fsflatDisplay,
  974.             DefaultScreen(fsflatDisplay));
  975. d284 2
  976. a285 2
  977.         aWindow->selection = WhitePixel(fsflatDisplay,
  978.             DefaultScreen(fsflatDisplay));
  979. d289 4
  980. a292 4
  981.     } else if (aWindow->background == WhitePixel(fsflatDisplay,
  982.         DefaultScreen(fsflatDisplay))) {
  983.     aWindow->selection = BlackPixel(fsflatDisplay,
  984.         DefaultScreen(fsflatDisplay));
  985. d294 2
  986. a295 2
  987.     aWindow->selection = WhitePixel(fsflatDisplay,
  988.         DefaultScreen(fsflatDisplay));
  989. d298 1
  990. a298 1
  991.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  992. d301 1
  993. a301 1
  994.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  995. d308 1
  996. a308 1
  997.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  998. d311 1
  999. a311 1
  1000.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1001. d317 1
  1002. a317 1
  1003.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1004. d320 1
  1005. a320 1
  1006.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1007. d326 1
  1008. a326 1
  1009.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1010. d329 1
  1011. a329 1
  1012.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1013. d335 1
  1014. a335 1
  1015.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1016. d338 1
  1017. a338 1
  1018.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1019. d345 1
  1020. a345 1
  1021.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1022. d348 1
  1023. a348 1
  1024.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1025. d355 1
  1026. a355 1
  1027.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1028. d358 1
  1029. a358 1
  1030.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1031. d365 1
  1032. a365 1
  1033.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1034. d368 1
  1035. a368 1
  1036.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1037. d375 1
  1038. a375 1
  1039.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1040. d378 1
  1041. a378 1
  1042.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1043. d385 1
  1044. a385 1
  1045.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1046. d388 1
  1047. a388 1
  1048.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1049. d395 1
  1050. a395 1
  1051.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1052. d398 1
  1053. a398 1
  1054.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1055. d405 1
  1056. a405 1
  1057.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1058. d408 1
  1059. a408 1
  1060.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1061. d415 1
  1062. a415 1
  1063.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1064. d418 1
  1065. a418 1
  1066.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1067. d425 1
  1068. a425 1
  1069.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1070. d428 1
  1071. a428 1
  1072.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1073. d435 1
  1074. a435 1
  1075.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1076. d446 1
  1077. a446 1
  1078.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1079. d449 1
  1080. a449 1
  1081.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1082. d456 1
  1083. a456 1
  1084.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication, "TxBorder"))
  1085. d459 1
  1086. a459 1
  1087.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1088. d466 1
  1089. a466 1
  1090.     if ((string = XGetDefault(fsflatDisplay, fsflatApplication,
  1091. d469 1
  1092. a469 1
  1093.         Util_StringToColor(fsflatDisplay, string)) == -1) {
  1094. d476 1
  1095. a476 1
  1096.     if ((geometry = XGetDefault(fsflatDisplay, fsflatApplication, "Geometry"))
  1097. d482 1
  1098. a482 1
  1099.     if ((font = XGetDefault(fsflatDisplay, fsflatApplication, "Font"))
  1100. d484 1
  1101. a484 1
  1102.     aWindow->fontPtr = XLoadQueryFont(fsflatDisplay, font);
  1103. d488 1
  1104. a488 1
  1105.         aWindow->fontPtr = Sx_GetDefaultFont(fsflatDisplay);
  1106. d491 1
  1107. a491 1
  1108.     aWindow->fontPtr = Sx_GetDefaultFont(fsflatDisplay);
  1109. d494 1
  1110. a494 1
  1111.     if ((font = XGetDefault(fsflatDisplay, fsflatApplication, "TitleFont"))
  1112. d496 1
  1113. a496 1
  1114.     aWindow->titleFontPtr = XLoadQueryFont(fsflatDisplay, font);
  1115. d502 1
  1116. a502 1
  1117.     aWindow->titleFontPtr = Sx_GetDefaultFont(fsflatDisplay);
  1118. d508 1
  1119. a508 1
  1120.     Sx_Panic(fsflatDisplay,
  1121. d514 2
  1122. a515 2
  1123.     if (FsflatCreate(aWindow, startDir) == NULL) {
  1124.         Sx_Panic(fsflatDisplay, "Couldn't create flat display window.");
  1125. d518 2
  1126. a519 2
  1127.     if (FsflatCreate(aWindow, NULL) == NULL) {
  1128.         Sx_Panic(fsflatDisplay, "Couldn't create flat display window.");
  1129. d524 9
  1130. d537 2
  1131. a538 2
  1132.     Fs_EventHandlerCreate(ConnectionNumber(fsflatDisplay), FS_READABLE,
  1133.         FsflatDisplayEventProc, NULL);
  1134. d541 2
  1135. a542 2
  1136.     while (fsflatWindowCount > 0) {
  1137.     while ((size = QLength(fsflatDisplay)) > 0) {
  1138. d545 1
  1139. a545 1
  1140.         XNextEvent(fsflatDisplay, &event);
  1141. d551 1
  1142. a551 1
  1143.     if ((size = QLength(fsflatDisplay)) > 0) {
  1144. d554 1
  1145. a554 1
  1146.     XFlush(fsflatDisplay);
  1147. d576 1
  1148. a576 1
  1149. FsflatDisplayEventProc(clientData, streamID, eventMask)
  1150. d586 1
  1151. a586 1
  1152.     XNextEvent(fsflatDisplay, &event);
  1153. d588 1
  1154. a588 1
  1155.     } while (QLength(fsflatDisplay) > 0);
  1156. d608 1
  1157. a608 1
  1158.     FsflatHandleMonitorUpdates();
  1159. d611 93
  1160. @
  1161.